package com.api.user.controller;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.model.PointsTransaction;
import com.api.user.service.PointsTransactionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.api.core.annotation.PowerEnable;
import io.swagger.annotations.*;



/**
* Created by wanghuiwen on 2021/03/26.
*/
@PowerEnable(name = "point交易明细",url = "/points/transaction")
@Api(value = "point交易明细", tags = {"point交易明细"})
@RestController
@RequestMapping("/points/transaction")
public class PointsTransactionController extends Ctrl{
    @Resource
    private PointsTransactionService pointsTransactionService;

    @ApiOperation(value = "point交易明细详细信息", tags = {"point交易明细"}, notes = "point交易明细详细信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id",required=true, value = "point交易明细id", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/detail",name="point交易明细详细信息")
    public Result detail(@RequestParam Integer id) {
        PointsTransaction pointsTransaction = pointsTransactionService.findById(id);
        return ResultGenerator.genSuccessResult(pointsTransaction);
    }

    @ApiOperation(value = "point交易明细列表信息", tags = {"point交易明细"}, notes = "point交易明细列表信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "search", value = "查询条件json", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "order", value = "排序json", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "page", value = "页码", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "size", value = "每页显示的条数", dataType = "String", paramType = "query", defaultValue = "10")
    })
    @PostMapping(value = "/list/user", name = "point交易明细列表信息")
    public Result list(
            @RequestParam(required = false) Long orderId,
            @RequestParam(defaultValue = "{}") String order,
            @RequestParam(defaultValue = "0") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            Authentication authentication) {

        Map<String,Object> params = new HashMap<>();
        params.put("orderId",orderId);
        params.put("userId",getAuthUser(authentication).getId());
        return pointsTransactionService.listUser(params,order,page, size);
    }

    @PostMapping(value = "/user/points", name = "point交易明细列表信息")
    public Result points(
            @RequestParam(required = false) Long orderId,
            @RequestParam() Long userId,
            @RequestParam(defaultValue = "{}") String order,
            @RequestParam(defaultValue = "0") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            Authentication authentication) {

        Map<String,Object> params = new HashMap<>();
        params.put("orderId",orderId);
        params.put("userId",userId);
        return pointsTransactionService.listUser(params,order,page, size);
    }

    @PostMapping(value = "/give/user", name = "赠送给用户")
    public Result points(Long toUser , BigDecimal point,Authentication authentication) {
        return pointsTransactionService.giveUser(toUser,point,getAuthUser(authentication).getId());
    }
}
